package com.ryl;

import java.util.Random;
import java.util.stream.IntStream;

/**
 * @Date 22:42
 * @Author ryl
 */

public class ThreadLocalTest {
    public static void main(String[] args) {
        ThreadLocal<String> threadLocal=new ThreadLocal<String> ();
        Random random=new Random (  );
        IntStream.range ( 0,5).forEach ( a->new Thread(()->{
            threadLocal.set ( a+" "+random.nextInt (100) );
            System.out.println ("线程和local值是什么"+ threadLocal.get ( ) );
            try {
                Thread.sleep ( 1000 );
            } catch (InterruptedException e) {
                e.printStackTrace ( );
            }
        }).start () );

    }
}
